<?php
namespace Base;
class RestResponse{
  private $isSuccess = false;
  private $errCode = 0;
  private $errMsg = null;
  private $response = null;
  private $rawData;

  public function __construct($data) {
    $this->rawData = $data;
    if (empty($this->rawData)) {
      $this->errMsg = 'empty response';
    }
    $tmp = @json_decode($this->rawData);
    if ($tmp == null) {
      $this->errMsg = 'illegal JSON response';
    } else {
      $this->isSuccess = $tmp->Success == 1 ? true : false;
      $this->errCode = $tmp->ErrorCode;
      $this->errMsg = $tmp->ErrorMsg;
      $this->response = $tmp->CallInfo;
    }
  }

  public function isSuccess() {
    return $this->isSuccess;
  }

  public function getErrorCode() {
    return $this->errCode;
  }

  public function getErrorMessage() {
    return $this->errMsg;
  }

  public function getResponse() {
    return json_decode(json_encode($this->response),true);
  }

  public function getRawData() {
    return $this->rawData;
  }
}
?>